package com.kuang.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: kuangshen-es-api
 * @description:
 * @author: 陈恩涛
 * @create: 2021-05-25 10:45
 **/

/**
 * 狂神的Spring两步骤：
 * 1、找对象
 * 2、放到Spring中待用
 * 3、如果是SpringBoot，就先去分析源码
 *      xxxxAutoConfiguration  xxxProperties
 */

@Configuration
public class ElasticSearchConfig {

    @Value("${clue.elasticsearch.host}")
    private String host;

    @Value("${clue.elasticsearch.port}")
    private int port;

    /**
     *  spring <bean id="restHighLevelClient" class="RestHighLevelClient">
      */

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(host, port, "http")));
        return client;
    }
}
